package com.seednia.module.core.profile.dto;

import java.util.Date;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import org.apache.commons.lang.StringUtils;

import com.seednia.foundation.framework.dto.AbstractRecord;
import com.seednia.foundation.framework.dto.Constants;
import com.seednia.foundation.framework.dto.ICriteria;
import com.seednia.foundation.framework.util.RecordUtils;
import com.seednia.module.core.search.util.AbstractQueryBuilder;
import com.seednia.module.core.user.dto.UserDto;

/**
 * Profile Criteria Class to query records
 *
 * @author Young Suk Ahn
 */
@XmlRootElement(name = "ProfileCriteria", 
		namespace = "http://seednia.com/core/1.0")
@XmlType(name = "ProfileCriteria")
@XmlAccessorType(XmlAccessType.PROPERTY)
public class ProfileCriteria extends ProfileDto implements ICriteria {

	public static final int FETCH_MINIMAL = 0; // Profile table only
	public static final int FETCH_TAGS = 1; // Profile table and tags
	public static final int FETCH_EXPERIENCES = 2; // Profile table and tags
	public static final int FETCH_ATTRIBUTES = 4; // Profile table and tags
	public static final int FETCH_RELATIONS = 8; // Profile table and tags
	
	private String nameLike = null;
	
	private int _fetchMode = FETCH_TAGS;

	/**
	 * 
	 */
	private static final long serialVersionUID = -5602953011658556350L;

	public ProfileCriteria(){
		RecordUtils.initCriteria(this);
		super.setCreatorDto(new UserDto()); // why I needed this?
		super.setStatus(Constants.INT_ANY);
		super.setWantTo(Constants.INT_ANY);
		super.setTimeCommitment(Constants.INT_ANY);
		super.setPrivacyLevel(Constants.PRIVACY_PUBLIC);
	}
	
	@Override
	public Date getCreatedBefore() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Date getCreatedAfter() {
		// TODO Auto-generated method stub
		return null;
	}
	
	/**
	 * Pre condition: the value text must be normalized (i.e. properly esacped special characters)
	 */
	@Override
	public void setSearchText(String value)
	{
		super.getCreatorDto().setFirstName(value);
		super.getCreatorDto().setLastName(value);
		super.getCreatorDto().setLcName(value);
		super.setCurrentLocation(value);
		super.setHighlight(value);
		
		super.setSkillTagNamesCsv(value);
		super.setInterestTagNamesCsv(value);
		//super.setStatus(ProfileDto.STATUS_AVAILABLE);
	}

	public String getNameLike() {
		return nameLike;
	}

	public void setNameLike(String nameLike) {
		this.nameLike = nameLike;
	}
	
	
	public int get_fetchMode() {
		return _fetchMode;
	}
	public void set_fetchMode(int _fetchMode) {
		this._fetchMode = _fetchMode;
	}
	public boolean has_fetchMode(int _fetchMode) {
		return (this._fetchMode & _fetchMode) > 0;
	}

	/**
	 * To create object from JSONP string
	 * Used by the REST framework when sending this object as parameter
	 * @param jsonStr
	 * @return
	 */
	public static ProfileCriteria fromString(String jsonStr) {
		ProfileCriteria retval = (ProfileCriteria) AbstractRecord.fromString(ProfileCriteria.class, jsonStr);
		return retval;
	}
}
